import user from '../store/modules/user.js'
import search from '../store/modules/search.js'
import home from '../store/modules/home'
import teacherHome from '../store/modules/teacher_home'
import teacherDetail from '../store/modules/teacher_detail'
import informationHome from '../store/modules/information_home'
import informationDetail from '../store/modules/information_detail'
import courses from '../store/modules/courses.js'
import personalCenter from '../store/modules/personal_center'
import professionHome from '../store/modules/profession_home.js'
import guide from './modules/guide'
import introduce from './modules/introduce.js'
import new_user_activity from './modules/new_user_activity'
import book from './modules/book'
import play from './modules/play'
import exam from './modules/exam'
import scHome from './modules/sc_home'
import kjscPlan from './modules/kjsc_plan.js'
import kjscCourse from './modules/kjsc_course'
import sprintActivity from './modules/sprint_activity'
import answerQuestion from './modules/answer_question.js'
import newExam from './modules/new_exam.js'
import exercises from './modules/exercises.js'

// 新的模块
import ceshi from './modules/ceshi.js'

export default {
  modules_map: {
    exam,
    play,
    user,
    home,
    teacherHome,
    teacherDetail,
    informationHome,
    informationDetail,
    search,
    courses,
    personalCenter,
    professionHome,
    guide,
    introduce,
    new_user_activity,
    book,
    scHome,
    kjscPlan,
    kjscCourse,
    sprintActivity,
    answerQuestion,
    newExam,
    exercises,
    ceshi
  },
  loadSingleModule(store, moduleName) {
    const moduleIsRegistered =
      store._modules.root._children[moduleName] !== undefined
    const stateExists = store.state[moduleName]
    if (typeof moduleName === 'string' && !moduleIsRegistered) {
      this.modules_map[moduleName] &&
        store.registerModule(moduleName, this.modules_map[moduleName], {
          preserveState: stateExists
        })
    }
  },
  loadModule(store, moduleName) {
    if (typeof moduleName === 'string') {
      this.loadSingleModule(store, moduleName)
    } else if (Array.isArray(moduleName)) {
      moduleName.forEach(item => {
        this.loadSingleModule(store, item)
      })
    }
  }
}
